﻿#ifndef PIPE_H
#define PIPE_H

//#include "PropertyData.h"
#include "refprop1.h"
#define M_g 9.8
#define M_PI 3.1415926

/**** 管子阻力 *****/

extern const char* PipeTypeForRough[7];

//粗糙度 mm SH/T3035
extern const double RoughLow[7];
extern const double RoughUp[7];


extern const char* PipeFittingAndValve[12];

//局部阻力系数 SH/T3035 DL/T5054 D3.1
extern const double LocalResistanceCoef[12];

extern const char* Shell[10];

extern const double ShellBlacknessLow[10];
extern const double ShellBlacknessUp[10];

/**
 * [DiWithVelocity]
 * @param  flowRate [kg/h]
 * @param  density  [kg/m3]
 * @param  velocity [m/s]
 * @return          [m]
 */
double Di_Velocity(double flowRate, double density, double velocity);


/**
 * [getFlowVelocity]
 * @param  flowRate [kg/h]
 * @param  density  [kg/m3]
 * @param  di       [m]
 * @return          [m/s]
 */
double FlowVelocity(double flowRate, double density, double di);


/**
 * [getRe]
 * @param  velocity [m/s]
 * @param  density  [kg/m3]
 * @param  visc     [Pa.s]
 * @param  di       [m]
 * @return          [Reynolds number]
 */
double Re(double velocity, double density, double visc, double di);


/**
 * [getFrictionalCoef  SH/T3035]
 * @param  di    [m]
 * @param  re
 * @param  rough [m]
 * @return       [摩擦系数]
 */
double FrictionalCoef(double di, double re, double rough);


/**
 * [getPipeDp]
 * @param  density        [kg/m3]
 * @param  velocity       [m/s]
 * @param  di             [m]
 * @param  length         [m]
 * @param  frictionalCoef
 * @return                [直管阻力 MPa]
 */
double StraightPipeDp(double density, double velocity, double di, double length, double frictionalCoef);


/**
 * [getLocalDp]
 * @param  density             [kg/m3]
 * @param  velocity            [m/s]
 * @param  localResistanceCoef [sum of localResistanceCoef]
 * @return                     [局部阻力 MPa]
 */
double LocalPipeDp(double density, double velocity, double localResistanceCoef);


/**
 * [getDp]
 * @param  pipeDp  [MPa]
 * @param  localDp [MPa]
 * @return         [总阻力 MPa]
 */
double PipeDp(double pipeDp, double localDp);


/**** Insulation *****/


double Ta(int model = 0, int place = 0, double t0 = 0);

double SpeedOfWind(int place = 0);

//GB50264 - 2013, 5.3.3 - 1
double D1_Q(double d0, double t0, double ta, double tc, double shtc, double Q);

double Q(double d0, double d1, double t0, double ta, double tc, double shtc); //W/m2

double q(double d, double Q);//W/m

double Ts(double ta, double shtc, double Q);

double Shtc(double d1, double ts, double ta, double w, double blackness);

double Tc(unsigned int insulId, double tm);

double Tm(double d0, double d1, double t0, unsigned int insulId, double backness, double ta, double w, double* ts);

//管托散热量
double PipeBracketDq(double length /* unit m */, double height /* unit m */, double t0 /* unit C */,
	double ta, double insulThk /* unit m */);

double PipeDpDt(char components[ncmax][refpropcharlength], double *x, long ncomp, double flowRate/* kg/h */,
	double t0 /* ℃ */, double p0 /* MPa */, double pipeDi/* m */, double pipeDo/* m */, double pipeD1/* m */,
	double pipeLength/* m */, double pipeRough, double localResistanceCoef, unsigned int insulId, double blackness,
	double blength/*单个管托长度 unit m*/, double bheight/*管托高度 unit m*/, int bnum/*管托数量*/, double* dt);

double AllowStress(double t);

double WeldingCoef(int weldingSideNum, double rtPercent);

double PipeThkY(const char *shapeCode, double t);

double PipeThickness(double D, double p, double s, double y, double weldingCoef, double w /*= 1*/, double c1 /*= 0.125*/, double c2 /*= 0.75*/, double c3 /*= 0*/);
#endif //PIPE_H
